<?php

namespace app\admin\model;

use think\Model;

class Collect extends Model
{
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = false;

    protected static function init()
    {
        self::afterDelete(function ($row) {
            $model = new \app\admin\model\department\Article;
            $row = $model->get($row['article_id']);
            $row->collect_num -= 1;
            $row->save();
        });
    }


    public function article()
    {
        return $this->belongsTo('app\admin\model\department\Article', 'article_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo('app\admin\model\Admin', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
